package net.sunzc.base.ui;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.sunzc.base.BaseApplication;
import net.sunzc.base.ContantsPool;
import org.xutils.x;

/**
 * Created by mac on 15/11/27.
 */
public abstract class BaseFragment extends Fragment implements ContantsPool {

    private boolean isInjected = false;
    protected BaseApplication mApplication;
    protected Activity mActivity;
    protected Context mActivityContext;
    protected Context mAppContext;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mApplication = (BaseApplication) mActivity.getApplication();
        mActivityContext = mActivity = getActivity();
        mAppContext = mApplication.getApplicationContext();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        isInjected = true;
        return x.view().inject(this, inflater, container);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        if (!isInjected) {
            x.view().inject(this, this.getView());
        }
    }


    protected void showToast(String content) {
    }

    protected void toActivity(Activity activity, Class targetActivity) {
    }

    protected void toActivity(Activity activity, Class targetActivity, Bundle data) {
    }

}
